package com.inei.cie;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.inei.cie.utilitarios.Sesion;

public class Configuracion_Activity extends Activity {

	EditText etDNI, etCP;
	Sesion sesion;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.configuracion);
		sesion = new Sesion(this);
		if (sesion.getESTADO() == 0) {
			IniciarComponentes();
		} else {
			Intent irLogin = new Intent(this, Login_Activity.class);
			startActivity(irLogin);
			finish();
		}
	}

	public void IniciarComponentes() {
		etDNI = (EditText) findViewById(R.id.etDNI);
		etCP = (EditText) findViewById(R.id.etCP);

	}

	public void configurar(View v) {
		if (etDNI.getText().toString().equals("")
				|| etDNI.getText().toString().length() != 8) {
			Toast.makeText(this, "Ingrese los 8 d\u00edgitos del n\u00famero de DNI",
					Toast.LENGTH_SHORT).show();
		} else if (etCP.getText().toString().equals("")
				|| etCP.getText().toString().length() != 5) {
			Toast.makeText(this,
					"Ingrese los 5 d\u00edgitos del C\u00f3digo Patrimonial",
					Toast.LENGTH_SHORT).show();
		} else {
			sesion.prepararEdit();
			sesion.setDNI(etDNI.getText().toString());
			sesion.setCP(etCP.getText().toString());
			sesion.setESTADO(1);
			sesion.terminarEdit();
			Intent irLogin = new Intent(this, Login_Activity.class);
			startActivity(irLogin);
			finish();
		}
	}

	public void salir(View v) {
		finish();
	}

}
